package com.gin.no_gay_alliance.utils;

import android.app.Activity;

import com.gin.nga.enums.NgaPhpApi;
import com.gin.no_gay_alliance.app.MyApplication;

import java.util.Locale;

/**
 * 复制工具类
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/18 12:21
 **/
public class CopyUtils {
    public static void copyLink(Activity activity, Long topicId, Long replyId) {
        String urlPrefix = MyApplication.getClient().getNgaDomain().domain + NgaPhpApi.read.path;
        boolean isTopic = replyId == null || replyId == 0;
        String text = isTopic ? (urlPrefix + "?tid=" + topicId) :
                (urlPrefix + "?to=1&pid=" + replyId);
        ClipboardUtils.setText(activity, text);
    }

    public static void copyBbsCode(Activity activity, Long topicId, Long replyId, String title, String username) {
        boolean isTopic = replyId == null || replyId == 0;
        title = title.replaceAll("\\[.+?]", "");
        String topicText = String.format(Locale.CHINA, "[tid=%d]%s[/tid]", topicId, title);
        String replyText = String.format(Locale.CHINA, "[pid=%d]%s 的回复 %d[/pid]", replyId, username, replyId);
        ClipboardUtils.setText(activity, isTopic ? topicText : replyText);
    }
}
